package com.nanhu.test.widget;

import com.nanhu.test.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ImageBtnWithText extends LinearLayout{
	
	private ImageButton mBtn;
	
	private TextView mTv;

	public ImageBtnWithText(Context context) {
		this(context, null);
	}
	
	public ImageBtnWithText(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater.from(context).inflate(R.layout.imagebtn_with_text, this, true);
		mBtn = (ImageButton)this.findViewById(R.id.btn1);
		mTv = (TextView)this.findViewById(R.id.text1);
		
		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ImageBtnWithText);
		CharSequence text = a.getText(R.styleable.ImageBtnWithText_android_src);
		if(text != null)mTv.setText(text);
		Drawable drawable = a.getDrawable(R.styleable.ImageBtnWithText_android_src);
		if(drawable != null)mBtn.setImageDrawable(drawable);
		String strAppend = a.getString(R.styleable.ImageBtnWithText_appendText);
		if(strAppend != null)mTv.setText(mTv.getText().toString() + strAppend);
		a.recycle();
	}
	
	public void setButtonImageResource(int resId){
		mBtn.setImageResource(resId);
	}
	
	public void setTextViewText(String text){
		mTv.setText(text);
	}
}
